package util;

import sun.misc.BASE64Decoder;

import javax.imageio.ImageIO;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

/**
 * Created by bowen on 2016/9/6.
 */
public class ImageUploadUtil {

    public static void GenerateImage(String filePath,String imageType,String imgStr) throws IOException {
        BASE64Decoder decoder = new BASE64Decoder();
        byte[] bytes = decoder.decodeBuffer(imgStr);
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        RenderedImage image = ImageIO.read(bais);
        File file = new File(filePath);
        if(!file.exists()){
            file.mkdirs();
            file.createNewFile();
        }
        ImageIO.write(image, imageType, file);
    }

}
